package be.fedict.eid.diagnostics.system.windows.proxies;

import com.sun.jna.IntegerType;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.PointerType;
import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.win32.StdCallLibrary;

public interface SetupAPI extends StdCallLibrary {
	
	SetupAPI INSTANCE = (SetupAPI) Native.loadLibrary("setupapi", SetupAPI.class);

	public static class Properties {
		public static int SPDRP_DEVICEDESC   					= (int) 0x00000000;
		public static int SPDRP_HARDWAREID 						= (int) 0x00000001;
		public static int SPDRP_COMPATIBLEIDS 					= (int) 0x00000002;
		public static int SPDRP_UNUSED0 						= (int) 0x00000003;
		public static int SPDRP_SERVICE 						= (int) 0x00000004;
		public static int SPDRP_UNUSED1 						= (int) 0x00000005;
		public static int SPDRP_UNUSED2 						= (int) 0x00000006;
		public static int SPDRP_CLASS 							= (int) 0x00000007;
		public static int SPDRP_CLASSGUID 						= (int) 0x00000008;
		public static int SPDRP_DRIVER 							= (int) 0x00000009;
		public static int SPDRP_CONFIGFLAGS 					= (int) 0x0000000A;
		public static int SPDRP_MFG          					= (int) 0x0000000B;
		public static int SPDRP_FRIENDLYNAME 					= (int) 0x0000000c;
		public static int SPDRP_LOCATION_INFORMATION 			= (int) 0x0000000D;
		public static int SPDRP_PHYSICAL_DEVICE_OBJECT_NAME 	= (int) 0x0000000E;
		public static int SPDRP_CAPABILITIES 					= (int) 0x0000000F;
		public static int SPDRP_ENUMERATOR_NAME 				= (int) 0x00000016;
	}
	
	public static class Flags {
		public static final int DIGCF_PRESENT	   = (int) 0x00000002;
		public static final int DIGCF_ALLCLASSES   = (int) 0x00000004;
	}	
	
	/*
	 * Type declarations
	 */
	public static class HANDLE extends PointerType {}
	public static class HWND extends HANDLE {}
    public static class HDEVINFO extends PointerType {}
	public static class ULONG_PTR extends IntegerType {
		private static final long serialVersionUID = -2935144517418582038L;
		public ULONG_PTR() { super(Pointer.SIZE, 0); }
    }
    public static class SP_DEVINFO_DATA extends Structure {
    	public int cbSize;
    	public GUID ClassGuid;
    	public int DevInst;
    	public int Reserved;
    }
    public static class GUID extends Structure
    {
            public int Data1;
            public short Data2;
            public short Data3;
            public byte Data4[] = new byte[8];
    }
    
	/**
	 * Return a device information set containing
	 * all of the devices in a specified class.
	 * 
	 * http://msdn.microsoft.com/en-us/library/ff551069(VS.85).aspx
	 * http://msdn.microsoft.com/en-us/library/ff541247(v=VS.85).aspx
	 */
    HDEVINFO SetupDiGetClassDevsA(
    		Pointer classGuid, 
    		String enumerator, 
    		int i, 
    		int flags);
    
    /**
     * Returns a SP_DEVINFO_DATA structure that specifies 
     * a device information element in a device information 
     * set.
     * 
     * http://msdn.microsoft.com/en-us/library/ff551010(VS.85).aspx
     */
    boolean SetupDiEnumDeviceInfo(
    		HDEVINFO DeviceInfoSet,
    		int MemberIndex,
    		SP_DEVINFO_DATA DeviceInfoData);

    /**
     * Retrieves a specified Plug and Play device property.
     * 
     * http://msdn.microsoft.com/en-us/library/ff551967(VS.85).aspx
     */
    boolean SetupDiGetDeviceRegistryPropertyA(
    		HDEVINFO DeviceInfoSet,
    		SP_DEVINFO_DATA DeviceInfoData,
    		int Property,
    		IntByReference PropertyRegDataType,
    		byte[] PropertyBuffer,
    		int PropertyBufferSize,
    		IntByReference RequiredSize);
    
    /**
     * Deletes a device information set and frees all associated memory.
     * 
     * http://msdn.microsoft.com/en-us/library/ff550996(VS.85).aspx
     */
    boolean SetupDiDestroyDeviceInfoList(
    		HDEVINFO DevInfoSet);
}